/////////////////////////////////////////////////////////////////////////////
/*/	
 *	Creator:		Joshua C. Rouzer
 *	Title:			Generator cpp
 *	Last Edited:	07/13/2013
 *	Summary:		
/*/
/////////////////////////////////////////////////////////////////////////////
#include "Generator.h"
#include "CSGD_TextureManager.h"
/////////////////////////////////////////////////////////////////////////////
// Function : 
// Notes	: 
/////////////////////////////////////////////////////////////////////////////
CGenerator::CGenerator(bool bTeamOne) : CDefenseStruct(bTeamOne) {
	m_eType = GENERATOR;

	SetImage(CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/Images/GeneratorArt.png")));

	SetWidth(32);
	SetHeight(32);

	if(bTeamOne)
		SetPosX(50);
	else
		SetPosX(750-(float)GetWidth());

	m_pTurret = nullptr;
}
/////////////////////////////////////////////////////////////////////////////
// Function		: Destructor
// Notes		: Cleans up any dynamic memory
/////////////////////////////////////////////////////////////////////////////
CGenerator::~CGenerator(){
	delete m_pTurret;
	m_pTurret = nullptr;
}
/////////////////////////////////////////////////////////////////////////////
// Function		: Update
// Parameters	: dT - Time elapsed since last update
// Notes		: 
/////////////////////////////////////////////////////////////////////////////
void CGenerator::Update(float dT){
	if( m_pTurret )
		m_pTurret->Update(dT);
}
/////////////////////////////////////////////////////////////////////////////
// Function		: Render
// Notes		: Renders the generator to the screen
/////////////////////////////////////////////////////////////////////////////
void CGenerator::Render(){
	CDefenseStruct::Render();

	// Draw Turret
	if( m_pTurret )
		m_pTurret->Render();
}
/////////////////////////////////////////////////////////////////////////////
// Function		: Upgrade
// Notes		: Increases stats based on level
/////////////////////////////////////////////////////////////////////////////
void CGenerator::Upgrade(){
	m_nLevel++;
	if(m_nLevel == 1){
		//Activate attacking generators (Turrets)
		if( GetTeam() == 1 )
			m_pTurret = new CTurret( true );
		else
			m_pTurret = new CTurret( false );

		m_pTurret->SetPosX( GetPosX() );
		m_pTurret->SetPosY( GetPosY() );

			//For now just change their displayed image
		SetImage(CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/Images/GeneratorArtLvl1.png")));
	}
	else if(m_nLevel == 4){
		//Increase generator health
		SetMaxHealth(GetMaxHealth() + 20);
		SetHealth(GetHealth() + 20);
		//Increase their attack
			//Maybe change image again
		SetImage(CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/Images/GeneratorArtLvl4.png")));
	}
	else if(m_nLevel != -1){
		//Increase generator health
		SetMaxHealth(GetMaxHealth() + 20);
		SetHealth(GetHealth() + 20);
	}
}